package com.sls.web.manager.freemarker;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.web.context.ContextLoaderListener;

import com.sls.web.manager.recharge.service.OperationService;

import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;

@Service
public class OperationDisplayMethod implements TemplateMethodModel {
	@Resource(name = "operationService")
	private OperationService operationService;

	@Override
	public Object exec(@SuppressWarnings("rawtypes") List arguments)
			throws TemplateModelException {
		try {
			String operation = null;
			if (operationService == null)
				operationService = (OperationService) ContextLoaderListener
						.getCurrentWebApplicationContext().getBean(
								"operationService");
			if (arguments != null && arguments.get(0) != null) {
				Map<String, String> map = operationService.operation();
				operation = arguments.get(0).toString();
				operation = map.get(operation);
				if (operation == null)
					operation = "";
				return operation;
			}
		} catch (Exception e) {
		}
		return "";
	}
}